namespace Warehouse

open System.Net.Mail
open FSharp.Windows

type EMailController(repository : DataModel.Repository) = 
    inherit Controller<EMailEvents, EMailModel>()

    override this.InitModel _ = ()

    override this.Dispatcher = function
        | Send ok -> Sync(this.Send ok)

    member this.Send ok model =
        use msg = new MailMessage()
        msg.Subject <- model.Subject
        msg.Body <- model.Body
        msg.To.Add model.Recipient
        msg.Attachments.Add model.Attachment
        use client = new SmtpClient()
        client.Send msg
        ok()

        

